<template>
    <div>
        <div class="m-alert">
            <span class="el-icon-info"></span>
            <span>仅支持具有外部联系人权限的成员使用历史朋友圈，需要员工自行填写朋友圈链接，至企业微信的对外展示信息中。</span>
        </div>
        <div class="interspaceH"></div>
        <el-form ref="form" :model="tagGroupForm" prop="name" label-width="100px" label-position="left">
            <el-form-item label="标签组名称">
                <el-input v-model="tagGroupForm.name"></el-input>
            </el-form-item>
            <el-form-item label="可见范围">
                <el-radio v-model="tagGroupForm.scope" label="1">全部员工</el-radio>
                <el-radio v-model="tagGroupForm.scope" label="2">部门可见</el-radio>
            </el-form-item>
            <el-form-item>
                <el-button type="text" icon="el-icon-circle-plus-outline" @click="showTagInput">添加标签</el-button>
                <el-input class="input-new-tag" style="width: 100px" v-if="tagVisible" v-model="tagValue" ref="saveTagInput" size="small" @keyup.enter.native="tagConfirmHandle" @blur="tagConfirmHandle"></el-input>
            </el-form-item>
            <el-form-item>
                <el-tag v-for="tag in tagGroupForm.tags" :key="tag.name" closable @close="closeTagHandle"> {{ tag }}</el-tag>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    name: "tag_add",
    data() {
        return {
            tagVisible: false,
            tagValue: '',
            tagGroupForm: {
                name: '',
                scope: '1',
                tags: []
            }
        }
    },
    mounted() {
    },
    methods: {
        showTagInput() {
            this.tagVisible = true;
            this.$nextTick(_ => {
                this.$refs.saveTagInput.$refs.input.focus();
            });
        },
        tagConfirmHandle() {
            let inputValue = this.tagValue;
            if (inputValue) {
                this.tagGroupForm.tags.push(inputValue);
            }
            this.tagVisible = false;
            this.tagValue = '';
        },
        closeTagHandle(tag) {
            this.tagGroupForm.tags.splice(this.tagGroupForm.tags.indexOf(tag), 1);
        },
    }
}
</script>

<style scoped>
.el-icon-info {
    color: #35abff;
    margin-right: 10px;
}

.m-alert {
    border: 1px solid #66b1ff;
    padding: 8px;
    background-color: rgba(190, 220, 255, 0.5);
    font-size: 14px;
    display: flex;
}

</style>
